<template>
    <div>
        <el-page-header content="首页" icon="" title="企业门户管理系统"></el-page-header>
        <el-card shadow="always" class="box-card" :body-style="{ padding: '20px' }">
            <el-row>
                <el-col :span="4">
                    <el-avatar :size="100" shape="circle" :src="avatarUrl" fit="fill"></el-avatar>

                </el-col>
                <el-col :span="20">
                    <h3 style="line-height: 100px;">欢迎回来，{{ store.state.userInfo.username }}，{{ welcomeText }}</h3>
                </el-col>
            </el-row>

        </el-card>

        <el-card shadow="always" :body-style="{ padding: '20px' }">
            <template #header>
                <div>
                    <span>公司产品</span>
                </div>
            </template>
            <el-carousel v-if="productArr.length" :interval="4000" type="card" height="350px">
                <el-carousel-item v-for="item in productArr" :key="item._id"
                    :style="{ background: `url(http://localhost:3000${item.cover})`, backgroundSize: 'cover', backgroundRepeat: 'no-repeat' }">
                    <h3 text="2xl" justify="center">{{ item.title }}</h3>
                </el-carousel-item>
            </el-carousel>
        </el-card>

    </div>
</template>


<script setup>
/* import axios from 'axios'
axios.get("/adminapi/user/home").then(res => console.log(res.data)) */
// https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png
import axios from 'axios'
import { useStore } from 'vuex';
import { computed, onMounted, ref } from 'vue';
const store = useStore()
// console.log(store.state.userInfo);
const avatarUrl = computed(() => store.state.userInfo.avatar ? 'http://localhost:3000' + store.state.userInfo.avatar : `https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png`)
const welcomeText = computed(() => new Date().getHours() < 12 ? '要开心每一天' : '喝杯咖啡看看抖音摸摸鱼吧')

const productArr = ref([])
onMounted(() => {
    getData()
})

const getData = async () => {
    const res = await axios.get(`/adminapi/product/list`)
    // console.log(res.data);
    productArr.value = res.data.data
    // console.log(productArr);
}


</script>


<style lang="scss" scoped>
.box-card {
    margin: 25px 0;
}

.el-carousel__item h3 {
    color: #ffffff;
    opacity: 0.75;
    line-height: 200px;
    margin: 0;
    text-align: center;
}

.el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
    background-color: #d3dce6;
}
</style>